#pragma once


#include "Common.h"
#include "ObjectPool.h"


class PageCache
{
public:
    static PageCache* GetInstance()
    {
        return &_sInst;
    }

    // 获取从对象到span的映射
	Span* MapObjectToSpan(void* obj);

	// 释放空闲span回到Pagecache，并合并相邻的span
	void ReleaseSpanToPageCache(Span* span);

    Span* NewSpan(size_t k);

	std::mutex _pageMtx;
private:
    SpanList _spanlists[NPAGES];
    ObjectPool<Span> _spanPool;

    std::unordered_map<PAGE_ID, Span*> _idSpanMap;

    PageCache()
    {}

    PageCache(const PageCache&) = delete;

    static PageCache _sInst;
};